(load "netpbm.lisp")

(let* ((s (open "test2.ppm"))
       (s2 (open "test2.pgm" :if-exists :supersede :direction :output :external-format :latin-1))
       (h (read-header s))
       (h2 (new-header (header-width h) (header-height h) 1 (header-maxval h))))
  (write-header h2 s2)
  (stream-image 
   (lambda (in out) 
     (setf (aref out 0) (truncate (/ (+ (aref in 0) (aref in 1) (aref in 2)) 3))) )
   h h2))
